// 导入useRoutes
import { useRoutes } from "react-router-dom";
// 导入useSelector
import { useSelector } from 'react-redux';
// 导入useState
import { useState } from "react";
// 导入权限组件
import Private from "../utils/Private";
// 导入路由按需加载
import LazyLoad from "../utils/LazyLoad";
import Admin from "../views/pages/admin"
// 404
import NoMatch from "../views/NoMatch";
// admin组件使用懒加载
// const home = LazyLoad("../views/admin/home/index");
// const village = LazyLoad("../views/admin/village/index");

// 导出路由
function RouterView() {
  const { leftRouteList } = useSelector((state: any) => state.auth);
  // 导入路由配置
  const routes = [
    {
      path: "/",
      element: LazyLoad("/LoginView")
    },
    {
      path: "/pages/*",
      element: <Admin/>,
      children: 
        [
          {
            path: "home",
            element: LazyLoad("/pages/home/home")
          },
          ...leftRouteList
        ]
    },
    {
      path: "*",
      element: <NoMatch />
    }
  ];
    // 获取路由
    const element = useRoutes(routes);
    // 返回路由
    return <>{element}</>;
}
export default RouterView
